<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>流程节点配置</title>
    <%@ include file="../../../include/easyui.jsp" %>
    <%@ include file="../../../include/pForm.jsp" %>
    <script type="text/javascript" src="/plug-in/jquery-easyui-1.5.1/plugins/datagrid-cellediting.js"></script>
    <style type="text/css">
    	#easyuiForm {margin: 0;padding: 0;width: 100%;height: 100%;}
    	#easyuiForm .fItem{padding: 2px;}
    	.roleTable{width: 100%;}
    	.roleTable tr td{padding: 3px;}
    	.roleTable .headTd{width: 33%;}
    	.roleTable .inputTd{width: 33%;}
    	.roleTable .inputTd select{width: 100%;height: 150px;}
    	.roleTable .inputTd input{width: 50px;}
    	.roleTable .inputTd textarea{width: 200px;height: 100px;}
    </style>
    <script type="text/javascript">
   		$(function(){
   			fn.resetForm();
   			fn.onBeforeSubmitForm = function(){
   				var $grid = $("#dataGrid");
   				var rows = $grid.datagrid("getRows");
   				for(var i=0,len=rows.length;i<len; i++){
   					var index = $grid.datagrid("getRowIndex",rows[i]);
   					$grid.datagrid("endEdit",index);
   				}
   				var data = $grid.datagrid("getData");
   				var formJson = JSON.stringify(data);
   				$("input[name=formJson]").val(formJson);
   				return true;
   			}
   			
   			/*经办角色添加和删除按钮控制*/
   			$(".inputTd input[type=button]").on("click",function(){
   				var rname = $(this).attr("rname"),
   					rname = rname.split("_");
   				var name = rname[0],
   					type = rname[1];
   				if(type=='d'){
   					$("select[name="+ name +"]").find("option:selected").remove();
   				}else{
   					$("select[name="+ name +"]").append('<option selected="selected">new</option>');
   				}
   			});
   			
   			/*活动名称和类型展示*/
   			$("input[name=nameShow]").val($("input[name=taskName]").val());
   			$("input[name=typeShow]").val($("input[name=taskType]").val());
   			
   			var taskId = $("input[name=taskId]").val();
   			var processKey = $("input[name=processKey]").val();
   			
   			$('#dataGrid').datagrid({   
   				idField:'fieldname',
   				singleSelect: true,
   				rownumbers: true,
   		     	queryParams: {
   		     		processKey: processKey,
   		     		taskId: taskId
   				},
   			    url:'/console/jForm/rewrite/getTaskFormConfig',    
   			    columns:[[ 
   			        {field:'field',title:'字段',width:160},
   			        {field:'title',title:'字段名称',width:120},
   			     	{field:'inform',title:'表单显示',width:60, rowspan:1,
			     		editor:{
			     			 type:'checkbox',  
			                 options:{ on: 'Y',  off: 'N' }  
			     		}
			     	},
			     	{field:'editable',title:'编辑',width:60, rowspan:1,
			     		editor:{
			     			 type:'checkbox',  
			                 options:{ on: 'Y',  off: 'N' }  
			     		}
			     	},
	   			    {field:'required',title:'必填',width:60, rowspan:1,
			     		editor:{
			     			 type:'checkbox',  
			                 options:{ on: 'Y',  off: 'N' }
			     		}
				     },
				     {field:'variable',title:'流程变量',width:60, rowspan:1,
				     		editor:{
				     			 type:'checkbox',  
				                 options:{ on: 'Y',  off: 'N' }  
				     		}
				     	}
   			    ]],
   			    onSelect:function(index, row){
   			    	//$('#dataGrid').datagrid("beginEdit", index);
   			    },
   			    onLoadSuccess:function(data){
   			    	var total = data.total || 0;
   			    	for(var index=0; index<total; index++){
   			    		$('#dataGrid').datagrid("beginEdit", index);
   			    	}
   			    }
   			});
   			
   			var taskType = $("input[name=taskType]").val();
   			if(taskType!='exclusiveGateway'){
	   			$('#tt').tabs('disableTab', 2);
   			}else{
   				$('#tt').tabs('disableTab', 0);
   				$('#tt').tabs('disableTab', 1);
   				$('#tt').tabs('disableTab', 3);
   				$('#tt').tabs('disableTab', 4);
   				$('#tt').tabs('select', 2);
   			}
   			
   			/*条件异步获取*/
   			var queryData = {taskId: $("input[name=taskId]").val(), key: $("input[name=processKey]").val()};
   			$.get("/console/activiti/resource/outgoingFlows",queryData ,function(result){
   				if(result){
   					var flow = null;
   					var tr = [];
   					for(var i=0,len=result.length;i<len; i++){
   						flow= result[i];
   						tr.push('<tr ><td  style="width:100%;">'+ flow.name +'</td>');
   						var textarea = '<textarea style="width:500px;" name="'+ flow.id +'"  id="'+ flow.id +'">'+ (flow.conditionExpression || '' ) +'</textarea>'
   						tr.push('<td style="width:100%;">'+ textarea +'</td></tr>');
   	   				}
   					$("#conditionConfigTable").append(tr.join(""));
   				}
   			});
   			
   			var param = {	
				processKey: $("input[name=processKey]").val(),
				processKey_searchType:'eq',
				taskId: $("input[name=taskId]").val(),
				taskId_searchType:'eq'
   			};
   			$.getJSON('/console/com.fs.flow.pojo.ProcessTaskConfig/json', param , function(data){
				if(data){
					fn.loadData(data);
				}
			}); 
   		});
    </script>
    
  </head>
  
  <body>
  	<form  id="easyuiForm"  method="post" action="/console/activiti/configTask" >
  		<input type="hidden" name="taskId" />
  		<input type="hidden" name="processKey" />
  		<input type="hidden" name="taskName" />
  		<input type="hidden" name="taskType" />
  		<input type="hidden" name="formJson" value="{}" />
  		
	    <div id="tt" class="easyui-tabs" style="width:100%;height:100%;">   
		    <div title="基本信息" style="padding:20px;display:none;">   
		       	<div class="fItem">   
			        <label for="name">活动名称：</label>
			        <input class="easyui-validatebox" style="border: 0;" type="text" name="nameShow" readonly="readonly"/>   
			    </div>  
			    <div  class="fItem">   
			        <label for="type">活动类型：</label>
			        <input class="easyui-validatebox" style="border: 0;" type="text" name="typeShow" readonly="readonly" />   
			    </div>  
			    <div class="fItem" style="margin-top:10px;">   
			    	<label><b>权限设置：</b></label>
			        <input type="checkbox" name="nextChoose" value="1" />   
			        <label for="nextUser">手动选择下一步办理人</label>
			        <input type="checkbox" name="upRight"  value="1" />  
			        <label for="nextUser">上传附件</label>
			        <input type="checkbox" name="downRight" value="1"  />  
			        <label for="nextUser">下载附件</label>
			    </div>
			    
			    <div  class="fItem" style="margin-top:10px;">  
			        <label><b>提醒方式：</b></label>
			        <input type="checkbox" name="emailSwitch" />  
			        <label for="emailSwitch">邮件通知</label>
			        <input type="checkbox" name="smsSwitch" />  
			        <label for="smsSwitch">短信通知</label>
			    </div>
			    
			    <div  class="fItem">  
			        <label><b>提交类型：</b></label>
			        <input type="radio" name="submitName" value="提交"/>  
			        <label>提交</label>
			        <input type="radio" name="submitName"  value="同意"/>  
			        <label>同意</label>
			        <input type="radio" name="submitName"  value="通过"/>  
			        <label>通过</label>
			        <input type="radio" name="submitName"  value="会签"/>  
			        <label>会签</label>
			        <input type="radio" name="submitName"  value="办结"/>  
			        <label>办结 </label>
			        <input type="radio" name="submitName"  value="完成"/>  
			        <label>完成 </label>
			    </div>   
			    
			     <div class="fItem" style="margin-top:10px;">   
			        <input type="checkbox" name="backSwitch" />  
			        <label for="backSwitch">允许回退</label>
			        <input type="checkbox" name="endSwitch" />  
			        <label for="endSwitch">允许终止</label>
			    </div> 
		       	 
		    </div>   
		    <div title="表单配置" data-options="closable:false" style="overflow:auto;padding:10px;display:none;">   
		           <table id="dataGrid" style="width: 95%;"></table>
		    </div>   
		    
		     <div id="conditionConfig" title="条件设置" data-options="closable:false" style="padding:10px;display:none;">   
		        <table id="conditionConfigTable" class="roleTable"></table>
		        
		    </div>  
		    <div title="经办角色" data-options="closable:false" style="padding:20px;display:none;">   
		        <table class="roleTable">
		        	<tbody>
		        		<tr>
		        			<td class="headTd">角色规则</td>
		        			<td class="headTd">人员</td>
		        			<td class="headTd">职务</td>
		        		</tr>
		        		<tr>
		        			<td class="inputTd">
		        				<textarea name="roleReg"  rows="" cols=""></textarea>
			        			<!-- 
			        			<select name="roleReg"  multiple="multiple">
			        				<option selected="selected">role</option>
			        			</select>
			        			 -->
		        			</td>
		        			<td class="inputTd">
		        				<textarea name="userReg"  rows="" cols=""></textarea>
		        				<!-- 
			        			<select name="userReg"   multiple="multiple">
			        				<option selected="selected" >user</option>
			        			</select>
		        				 -->
		        			</td>
		        			<td class="inputTd">
		        				<textarea name="positionReg"  rows="" cols=""></textarea>
		        				<!-- 
			        			<select name="positionReg"   multiple="multiple">
			        				<option selected="selected" >position</option>
			        			</select>
		        				 -->
		        			</td>
		        		</tr>
		        		<tr>
		        			<td class="inputTd"><input type="button" rname="roleReg_a" value="添加" />&nbsp;<input type="button" rname="roleReg_d"  value="移除" /></td>
		        			<td class="inputTd"><input type="button" rname="userReg_a"  value="添加" />&nbsp;<input type="button" rname="userReg_d"  value="移除" /></td>
		        			<td class="inputTd"><input type="button" rname="positionReg_a"  value="添加" />&nbsp;<input type="button" rname="positionReg_d"  value="移除" /></td>
		        		</tr>
		        	</tbody>
		        </table>   
		    </div>   
		    <div title="知会人员" data-options="closable:false" style="padding:20px;display:none;">   
		        <textarea name="noticeUsers" rows="4" style="height: 200px;width: 100%;"></textarea>
		    </div>   
		</div>  
  	</form>
  </body>
</html>
